% TABLE2A.M

clear;
randn('seed',123)

% Table 2a: Daily WTI price, 1983-2008
load data2a.txt;
nobs=data2a(:,1); % Number of news announcements
n=length(nobs);   % Number of mining trials left 
vary=data2a(:,2); % Variance of dependent variable (different for each
                  % regression as sample differs).
varx=data2a(:,3); % Variance of the n individual regressors

nrep=100000;                          
for i=1:nrep;

    tstat=zeros(n,1);
    for j=1:n
        y=sqrt(vary(j,1)).*randn(nobs(j,1),1);
        x=sqrt(varx(j,1)).*randn(nobs(j,1),1);
        tstat(j,1)=ols(y,[ones(nobs(j,1),1) x]);
    end;
    
    % Take supremum over n t-statistics for each trial i:
    tmax(i,1)=max(tstat);
    clear y x tstat;
end;

% Compute 5% and 10% one-sided critical values of the distribution of the 
% sup-t-statistic allowing for data mining
%disp([n prctile(tmax,(1-0.05)*100)])
%disp([n prctile(tmax,(1-0.10)*100)])

% P-values
sum(sort(tmax)>-1.08)/length(tmax)

